/**
 * @description 右侧组件属性面板
 * @author 大肘子
 */

import React, { FC, useEffect } from "react";
import { QuestionParagraphType } from "./type";
import { Checkbox, Form, Input } from "antd";
const { TextArea } = Input;
const PropsComponent: FC<QuestionParagraphType> = (props) => {
  const { title, iscenter, onchange, disabled } = props;
  const [form] = Form.useForm();
  //如果是相同类型的组件面版就需要这个进行数据的更新
  useEffect(() => {
    form.setFieldsValue({ title, iscenter });
  }, [title, iscenter]);
  function handleValueChange() {
    if (onchange) {
      onchange(form.getFieldsValue());
    }
  }
  return (
    <Form layout="vertical" initialValues={{ title, iscenter }} form={form} onValuesChange={handleValueChange} disabled={disabled}>
      <Form.Item label="输入框" name="title" rules={[{ required: true, message: "请输入段落内容" }]}>
        <TextArea rows={2} />
      </Form.Item>
      <Form.Item name="iscenter" valuePropName="checked">
        <Checkbox>是否居中</Checkbox>
      </Form.Item>
    </Form>
  );
};

export default PropsComponent;
